package com.leapp.sk.viewdelegate.adapter.im

import android.content.Context
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.RequestManager
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.example.mvp.delegate.BaseAdapterDelegate
import com.example.mvp.view.GlideCircleTransform

import com.leapp.sk.R
import com.leapp.sk.bean.EmojiconEntity
import com.leapp.sk.util.im.EmojiconUtils

/**
 * 表情适配器视图托管层
 * @author  chaohaipeng  on 2018/7/13.
 */
class EmojiconGridAdapterDelegate : BaseAdapterDelegate() {
    /**
     * 图片加载操作
     */
    var mRequestOptions: RequestOptions = RequestOptions()
    override fun getOptionsMenuId(): Int {
        return 0
    }

    override fun initWidget() {
    }

    override fun onDestroy() {
    }

    override fun initLayoutRes(): Int {
        return R.layout.sk_emoj_nom_expression
    }

    /**
     * 设置数据
     */
    fun setData(context: Context, emojicon: EmojiconEntity){
          val iv_semne_expression =getView<ImageView>(R.id.iv_semne_expression)
           if (EmojiconUtils.DELETE_KEY.equals(emojicon.emojiText)) {
               iv_semne_expression.setImageResource(R.mipmap.icon_emoji_delete)
           } else {
               if (emojicon.icon !== 0) {
                   iv_semne_expression.setImageResource(emojicon.icon)
               } else if (emojicon.iconPath != null) {
                   val mRequestManager:RequestManager = Glide.with(context)
                   mRequestOptions.diskCacheStrategy(DiskCacheStrategy.NONE)
                   mRequestOptions.skipMemoryCache(true)
                   mRequestOptions.error(R.mipmap.ease_default_expression)
                   mRequestOptions.transforms(GlideCircleTransform(context))
                   mRequestManager?.load(emojicon.iconPath)
                           ?.thumbnail(0.2f)
                           ?.apply(mRequestOptions)
                           ?.into(iv_semne_expression)

               }
           }



       }



}